package com.prototype.demo03;

/**
 * 模拟齐天大圣变身术
 */
public class TheGreatestSage {
    private Monkey monkey = new Monkey();

    // 这里模拟变幻出很多个齐天大圣
    public void change()  {
        Monkey copyMonkey;


        for (int i = 1; i <= 10; i++) {
            copyMonkey = (Monkey) monkey.clone();
            System.out.println("Monkey King's birth date="+ monkey.getBirthday());
            System.out.println("Copy monkey's birth date="+ copyMonkey.getBirthday());
            System.out.println("Monkey King birthday == Copy Monkey birthday?"+ (monkey.getBirthday() == copyMonkey.getBirthday()));
            System.out.println("Monkey King == Copy Monkey? "+ (monkey == copyMonkey));
            // 金箍棒相等,说明持有的同一根金箍棒,而不是两根.这就是浅层克隆.克隆的是引用对象的地址
            System.out.println("Monkey King's Staff == Copy Monkey's Staff? "+ (monkey.getStaff() == copyMonkey.getStaff()));
            System.out.println("<<======================裂变第 "+ i +" 个猴孙");
        }
    }


}
